const Mongoose = require("./db");
const fee = require("../counts/fee.js");
const formatDateHelper = require('../utils/formatDateHelper.js')
const feeSchema = new Mongoose.Schema({
	id: {
		type: Number,
		unique: true,
	},
	time: String,
	house_id: Number,
	room_id: Number,
	water_unit: Number,
	water: Number,
	electricity_unit: Number,
	electricity: Number,
	comprehensive: Number,
	sum_total: Number,
	status: Number,
	create: {
		type: String,
		default: formatDateHelper.date() 
	},
	modify: {
		type: String,
		default: formatDateHelper.date()
	}
})


feeSchema.pre("save", async function(next) {
	const self = this;
	try {
		if (!self.id) {
			self.id = await fee.getNextSequenceValue("id");
		}
	} catch (err) {
		next(err);
	}
});

const feeModel = Mongoose.model("fees", feeSchema);

module.exports = feeModel;